#include <iostream>
#include <BinaryTree.hpp>
#include <vector>

using namespace std;
class Solution
{
public:
    int rob(TreeNode *root)
    {
        auto [r, ur] = rob_unrob(root);
        return max(r, ur);
    }

    pair<int, int> rob_unrob(TreeNode *root)
    {
        if (root == nullptr)
        {
            return {0, 0};
        }
        auto [lr, lu] = rob_unrob(root->left);
        auto [rr, ru] = rob_unrob(root->right);
        return {root->val + lu + ru, max(lr, lu) + max(rr, ru)};
    }
};

int main()
{
    cout << "Code337" << endl;
    Solution s;
    // TreeNode *root = CreatTree("3,2,3,null,3,null,1", "null");
    TreeNode *root = CreatTree("[2,1,3,null,4]", "null");
    cout << s.rob(root) << endl;
    return 0;
}